package org.hot100_3;

import java.util.ArrayList;
import java.util.List;

public class leetcode46 {

    List<List<Integer>> res = new ArrayList<>();
    List<Integer> item = new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        backtracking(nums,0);
        return res;
    }

    private void backtracking(int[] nums, int index) {
        if (index == nums.length) {
            res.add(new ArrayList<>(item));
            return;
        }

        for (int i = 0; i < nums.length; i++) {
            if (item.contains(nums[i])) {
                continue;
            }
            item.add(nums[i]);

            backtracking(nums, index + 1);

            item.remove(item.size() - 1);

        }
    }
}
